<template>
    <view>
        <camera mode="scanCode" device-position="back" flash="off" @scancode="scancode" class="scan"></camera>
    </view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {			
		},
		methods: {
			scancode(res) {
				// console.log('扫码成功');
				// console.log(res);
				// console.log(res.detail.result)
				// this.isbn = res.detail.result;
				this.getBookinfo(res.detail.result);				
			},
			getBookinfo(isbn) {
				uni.request({
				    url: 'https://www.yedushu.cn/api/scanisbn', // 根据isbn搜索
					data: {
						isbn: isbn
					},
				    success: (res) => {
				        console.log(JSON.stringify(res.data));
						if(res.data != null && res.data != "")
						{
							// 跳转到书籍详情页面
							uni.redirectTo({
							    url: '../books/bookinfo?bookid=' + res.data.book_id + '&bookname=' + res.data.book_name
							});
						} else {
							// 没有搜索到图书的提示
							uni.redirectTo({
							    url: './scanisbn_tishi'
							});
						}
				    }
				});					
			}
		}
	}
</script>

<style>
	.scan {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		/* background-color: #007AFF; */
	}
</style>
